package handler

import (
	"github.com/gin-gonic/gin/binding"
	"log"
	"nearby/biz/common"
	"nearby/biz/model"
	"nearby/biz/service"

	"github.com/gin-gonic/gin"
)

// WxRegister [Get] /nearby/user_center/wx_register
func WxRegister(c *gin.Context) {
	// 拿wx_code和用户的昵称、头像来注册
	// 注册成功后返回一个token
	req := &model.WxRegisterRequest{}
	if err := c.ShouldBindBodyWith(req, binding.JSON); err != nil {
		c.JSON(400, err.Error())
		return
	}
	log.Printf("WxRegister req: %+v", req)
	var ss service.WxRegisterService
	resp, err := ss.Execute(c, req)
	log.Printf("WxRegister resp: %+v, err: %+v", resp, err)
	if err != nil {
		common.WriteError(c, err)
		return
	}
	c.JSON(200, resp)
}
